<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>电视端人才政策</title>
    <link href="/coopen/css/index.css" rel="stylesheet" />
    <script type="text/javascript" src="/coopen/js/echarts.common.min.js"></script>
    <script type="text/javascript" src="/coopen/js/jquery-1.8.3.min.js"></script>
    <style type="text/css">
        .bd{
            height: 520px;
            overflow: hidden;
            position: relative;
        }
        .picList{
            position: absolute;
        }
    </style>
</head>

<body>
<div class="main" id="main">
    <div class="index_top">
        <div class="title">
            <a href="javascript:window.android.startSign(1);">
                <img src="/coopen/images/return.png" />
                <span>{{$category['cat_name']}}</span>
            </a>
        </div>

    </div>
    <!--轮播-->
    <div class="picScroll-top">
        <!--切换内容-->
        <div class="bd">
            <ul class="tab picList" id="contentList">
            </ul>
        </div>
        <!--end-->
        <!--上下切换按钮-->
        <div class="hd">
            <a class="next" id="nextPage"><img src="/coopen/images/down.png" /></a>
            <a class="prev" id="prevPage"><img src="/coopen/images/top.png" /></a>
        </div>
        <!--end-->

    </div>
</div>
<!--弹窗-->

<script type="text/javascript">
    function getNews ($id,prev,next) {
        $.get(
            '/coopen/'+$id+'/page',
            {
                prev:prev,
                next:next
            },
            function (e) {
                $('.popBox').html(e);
                $(".popBox").show();
            }
        )
    }
    $(function(){

        $(document).on('click','.Box',function () {
            var _id = $(this).attr('new-id');
            $("[newBox="+_id+"]").show();

        })
        $(document).on('click','.checkNew',function () {
            var _id = $(this).attr('new-id');
            $(".popBox").hide()

            $("[newBox="+_id+"]").show();

        })
        $(document).on('click',".popBox .close",function(){
            $(".popBox").hide()
        });
        var limit = 8;
        var _url = '{{route('coopen.post-list-ajax')}}';
        var page= 1;
        var len = $(".picList").find("li").length;
        var hei = $(".picList").find("li").height()*2;
        var page_count = Math.ceil(len/2);
        var p=1;
        var more= true;
        var touchs =true;
        $("body").on('touchstart', function(e) {
            var touch1 = e.originalEvent.targetTouches[0];
            x1 = touch1.pageX;
            y1 = touch1.pageY;
        });
        $("body").on('touchmove',function(e){
            var touch2 = e.originalEvent.targetTouches[0];
            var x2 = touch2.pageX;
            var y2 = touch2.pageY;
            if(touchs){
                if (!$(".picList").is(":animated")) {
                    if (y2-y1<0) {
                        if(more){
                            touchs=false;
                            $.get(
                                _url,
                                {
                                    limit:limit,
                                    page:p++,
                                    category_id:{{$category['id']}}
                                },
                                function (e) {
                                    if(e!=''){
                                        $('#contentList').append(e);
                                        len = $(".picList").find("li").length;
                                        hei = $(".picList").find("li").height()*2;
                                        page_count = Math.ceil(len/2);
                                        if(page!=page_count){
                                            $(".picList").animate({top:'-='+hei},'normal');
                                            page++;
                                        }else{

                                        }
                                        if(page!=1){
                                            $('#prevPage').show()
                                        }else{
                                            $('#prevPage').hide()
                                        }
                                    }else{
                                        more =false;
                                    }
                                    touchs=true;

                                }
                            )
                        }else{
                            if(page!=page_count){
                                $(".picList").animate({top:'-='+hei},'normal');
                                page++;
                            }else{

                            }
                            if(page!=1){
                                $('#prevPage').show()
                            }else{
                                $('#prevPage').hide()
                            }

                        }
                    }else{

                        if(page == 1){
                        }else{
                            $(".picList").animate({top:'+='+hei},"normal");
                            page--;
                        }
                        console.log(page);
                        if(page!=1){
                            $('#prevPage').show()
                        }else{
                            $('#prevPage').hide()
                        }
                    }
                }

            }


        })
        $(".next").click(function(){
            if (!$(".picList").is(":animated")) {
                if(more){
                    $.get(
                        _url,
                        {
                            limit:limit,
                            page:p++,
                            category_id:{{$category['id']}}
                        },
                        function (e) {
                            if(e!=''){
                                $('#contentList').append(e);
                                len = $(".picList").find("li").length;
                                hei = $(".picList").find("li").height()*2;
                                page_count = Math.ceil(len/2);
                                if(page == page_count){

                                }else{
                                    $(".picList").animate({top:'-='+hei},'normal');
                                    page++;
                                }
                                if(page!=1){
                                    $('#prevPage').show()
                                }else{
                                    $('#prevPage').hide()
                                }
                            }else{
                                more =false;
                            }

                        }
                    )
                }else{
                    if(page == page_count){

                    }else{
                        $(".picList").animate({top:'-='+hei},'normal');
                        page++;
                    }

                    if(page!=1){
                        $('#prevPage').show()
                    }else{
                        $('#prevPage').hide()
                    }
                }
            }
        })
        $(".prev").click(function(){
            if (!$(".picList").is(":animated")) {
                if(page == 1){

                }else{
                    $(".picList").animate({top:'+='+hei},"normal");
                    page--;
                }
                if(page!=1){
                    $('#prevPage').show()
                }else{
                    $('#prevPage').hide()
                }
            }
        })
        $.get(
            _url,
            {
                limit:8,
                page:p,
                category_id:{{$category['id']}}
            },
            function (e) {
                p++;
                $('#prevPage').hide();
                if(e!=''){
                    $('#contentList').append(e);
                    len = $(".picList").find("li").length;
                    hei = $(".picList").find("li").height()*2;
                    page_count = Math.ceil(len/2);

                }else{
                    $('#nextPage').hide();

                    more =false;
                }

            })
    })
</script>
</body>

</html>